/*
 * Screen.cpp
 *
 *  Created on: Aug 30, 2012
 *      Author: javu
 */
#include "Screen.h"


Screen::Screen(int width, int height,const char* bg, const char* name){
	this->width= width;  //dimensiones de la pantalla
	this->height=height;
	this->bg = bg; //path de la imagen de fondo
	this->name = name;//Nombre de ventana
	this->rcMainSprite.x = 0;
	this->rcMainSprite.y = 0;
};

Screen::Screen(){
	this->width=1000; //dimensiones arbitrarias de pantalla
	this->height=1000;
};


int Screen::startSdl(){
	// Start SDL
	cout<<"Starting SDL"<< endl;
	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		printf("No se pudo iniciar SDL: %s\n",SDL_GetError());
		return -1;
	}
	std::cout<<"Sucsess Starting SDL"<< endl;
	//Seteamos titulo de ventana
	cout<<"Setting title"<< endl;
	SDL_WM_SetCaption(this->name, this->name);
	cout<<"Setting video mode"<< endl;
	this->screen = SDL_SetVideoMode(this->width, this->height, 0, 0);
	if(!screen){
		cout<<"No se pudo iniciar la pantalla: %s"<<SDL_GetError();
		return -1;
	}
	cout<<"SDL Started Sucsesfully"<< endl;
	return 0;
};


void Screen::load_sprite(){
	cout<<"Loading Sprite"<< endl;

	char pathCompleto[256];

	snprintf(pathCompleto, sizeof(pathCompleto), "%s/%s", getenv("CONF_DIR"), "sprite.bmp");
	this->temp = SDL_LoadBMP(pathCompleto);
	this->main_sprite = SDL_DisplayFormat(temp);
	SDL_FreeSurface(temp);
};

void Screen::load_background(){
	cout<<"Loading Background"<< endl;
	this->temp = SDL_LoadBMP(this->bg);
	this->backGround = SDL_DisplayFormat(temp);
	SDL_FreeSurface(temp);
};

SDL_Surface* Screen::getMainSprite(){
	return (this->main_sprite);
};

SDL_Surface* Screen::getBackGround(){
	return (this->backGround);
};

SDL_Surface* Screen::getScreen(){
	return (this->screen);
};

SDL_Rect* Screen::getRcMainSprite(){
	return(&(this->rcMainSprite));
};
SDL_Rect* Screen::getRcBackGround(){
	return(&(this->rcBackGround));
};

int Screen::getHeight(){
	return this->height;
};

int Screen::getWidth(){
	return this->width;
};
